package day10;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;

import org.junit.Test;

import day9.Student;

public class SetMapDemo {

	@Test
	public void test1() {
		ArrayList<Student> list = new ArrayList<Student>();
		Student student1 = new Student(1, "zhangsan1", 23, "男");
		Student student2 = new Student(2, "zhangsan2", 23, "男");
		Student student3 = new Student(3, "zhangsan3", 23, "男");
		list.add(student1);
		list.add(student2);
		list.add(student3);
		list.add(student1);
		for (Student student : list) {
			System.out.println(student);
		}
		System.out.println("-------------------");
		// Set也是集合，HashSet是实现了Set这个接口
		// HashSet里面的元素是不能重复，取出的顺序不一定是你放进去的顺序
		HashSet<Student> set = new HashSet<Student>();
		set.add(student1);
		set.add(student2);
		set.add(student3);
		set.add(student1);
		for (Student student : set) {
			System.out.println(student);
		}
	}

	@Test
	public void test2() {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put("CN", "中华人民共和国");
		map.put("US", "美利坚合众国");
		map.put("UK", "大不列颠");

		String value1 = map.get("CN");
		System.out.println(value1);
		String value2 = map.get("UK");
		System.out.println(value2);

		Set<Entry<String, String>> set = map.entrySet();
		for (Entry<String, String> entry : set) {
			String key = entry.getKey();
			String value = entry.getValue();
			System.out.println("key: " + key + ", value: " + value);
		}

		// keySet将map里面所有的key放到set集合里面
		Set<String> keySet = map.keySet();
		for (String key : keySet) {
			String value = map.get(key);
			System.out.println("key: " + key + ", value: " + value);
		}

	}
	
	@Test
	public void test33() {
		System.out.println((char)43);
		int[] array = new int[3];
		// ArrayIndexOutofBoundsException
		for (int i = 0; i <= array.length; i++) {
			System.out.println(array[i]);
		}
		for (int i : array) {
			System.out.println(i);
		}
	}
}
